<template>
	<view>
		<view class="search-cell suspended-top">
			<view class="search-item">
				<view class="screen-btn" @click="orderSort"><text>排序</text><label class="iconfont icon-ym-paixu"></label></view>
				<view class="screen-btn" @click="cucreen"><text>筛选</text><label class="iconfont icon-ym-shaixuan"></label></view>
			</view>
		</view>
		
		<view class="search-input">
			<label class="iconfont icon-sousuo" />
			<input type="text" confirm-type="search" class="font-size24" placeholder="搜索" />
		</view>
		
		<scroll-view class="content" scroll-y @scrolltolower="scrollButtonClick" id="height" :style="'height:' + height + 'px ;'">
			<view class="jn-grid-list">
				<uni-swipe-action style="width: 100%; padding:0rpx 30rpx;">
					<uni-swipe-action-item v-for="(list,index) in dataList" :options="options" :key="index" @click="removeDetils(list,index)">
						<view class="item" @click.stop="featuresDetail(list)">
							<view class="jn-item-cell">
								<view class="jn-list-cell cell" v-for="(item,index) in list" :options="options" :key="index" style="">
									<view class="jn-item-cell-left">
										<view class="color-9A9A9A"  style="width: 100%;">{{item.label}}: {{item.value}}</view>
									</view>
								</view>
							</view>
						</view>
					</uni-swipe-action-item>
				</uni-swipe-action>
			</view>
			<view class="noContent" v-show="isNoData">
				<img :src="nodata" alt="">
				<view class="">
					暂无数据
				</view>
			</view>
		</scroll-view>
		<!-- 新建表单按钮 -->
		<uni-fab :pattern="pattern" :horizontal="horizontal" :vertical="vertical" :direction="direction" @creqateopen="creqateopen"></uni-fab>
		<!-- 排序 -->
		<uni-popup type="top" mode="insert" :mask-click="true" ref="popup">
			<view class="popup-box" style="overflow-y: scroll;height: 600rpx;" v-if="sortData.length != 0">
				<block v-for="(sortData,index) in sortData" :key="index">
					<view class="staff" @tap="billAsc(sortData)" >
						<view class="staffinfo border-bottom-E3E3E5" hover-class="uni-list-cell-hover">
							<view class="staffname"></text><label>{{sortData.label}}升序</label></view>
							<view class="advanceicon">
								<radio :data-radio="index" :checked="isBillAsc" :value="index+''" :disabled="scanType"/>
							</view>
						</view>
					</view>
					<view class="staff" @tap="billDesc(sortData)" >
						<view class="staffinfo border-bottom-E3E3E5" hover-class="uni-list-cell-hover">
							<view class="staffname"></text><label>{{sortData.label}}降序</label></view>
							<view class="advanceicon">
								<radio :data-radio="index" :checked="isBillAsc" :value="index+''" :disabled="scanType"/>
							</view>
						</view>
					</view>
				</block>
			</view>
			<view class="noContent" v-else style="padding: 100rpx 0;">
				<img :src="nodata" alt="">
				<view class="">
					未添加排序字段
				</view>
			</view>
		</uni-popup>
		<!-- 筛选 -->
		<uni-popup type="top" mode="insert" :mask-click="true" ref="cucreen">
			<form @reset="reset" v-if='filter.length != 0'>
				<view :style="{'height':filterHeight+'rpx'}" style="overflow: scroll;background-color: #FFFFFF;">
					<view class="popup-box" v-for="(filterData,index) in filter" :key="index">
						<!-- 输入框 -->
						<view v-if="filterData.jnpfKey == 'comInput' || filterData.jnpfKey == 'textarea'" v-model="filterData.prop">
							<view class="staff staffinfo border-bottom-E3E3E5" @tap="filterFn">
								<view class="staffname"></text><label>{{filterData.label}}</label></view>
								<view class="advanceicon inputBox">
									<input type="text" placeholder="请输入" @input="hideKeyboard($event,filterData.prop)" v-model="formData[filterData.prop]">
								</view>
							</view>
						</view>
						
						<!-- 树组件 -->
						<view v-if="filterData.jnpfKey == 'comSelect'" @tap='salesmanName(filterData.prop,filterData.multiple,filterData.jnpfKey)'>
							<view class="staff staffinfo border-bottom-E3E3E5" @tap="filterFn">
								<view class="staffname"></text><label>{{filterData.label}}</label></view>
								<view class="advanceicon inputBox">
									<input type="text" placeholder="请输入" @input="hideKeyboard($event,filterData.prop)" v-model="resulData[filterData.prop]">
								</view>
							</view>
						</view>
						
						<view v-if="filterData.jnpfKey == 'depSelect'" @tap='salesmanName(filterData.prop,filterData.multiple,filterData.jnpfKey)'>
							<view class="staff staffinfo border-bottom-E3E3E5" @tap="filterFn">
								<view class="staffname"></text><label>{{filterData.label}}</label></view>
								<view class="advanceicon inputBox">
									<input type="text" placeholder="请输入" @input="hideKeyboard($event,filterData.prop)" v-model="resulData[filterData.prop]">
								</view>
							</view>
						</view>
						
						<view v-if="filterData.jnpfKey == 'posSelect'" @tap='salesmanName(filterData.prop,filterData.multiple,filterData.jnpfKey)'>
							<view class="staff staffinfo border-bottom-E3E3E5" @tap="filterFn">
								<view class="staffname"><label>{{filterData.label}}</label></view>
								<view class="advanceicon inputBox">
									<input type="text" placeholder="请选择" @input="hideKeyboard($event,filterData.prop)" v-model="resulData[filterData.prop]">
								</view>
							</view>
						</view>
						
						<view v-if="filterData.jnpfKey == 'userSelect'" @tap='salesmanName(filterData.prop,filterData.multiple,filterData.jnpfKey)'>
							<view class="staff staffinfo border-bottom-E3E3E5" @tap="filterFn">
								<view class="staffname"><label>{{filterData.label}}</label></view>
								<view class="advanceicon inputBox">
									<input type="text" placeholder="请选择" v-model="resulData[filterData.prop]">
								</view>
							</view>
						</view>
						
						<!-- 区域选择 -->
						<view v-else-if="filterData.jnpfKey == 'address'" @tap.stop="showMulLinkageThreePicker(filterData.prop)">
							<view class="staff staffinfo border-bottom-E3E3E5">
								<view class="staffname"><label>{{filterData.label}}</label></view>
								<view class="advanceicon inputBox">
									<input type="text" v-model="resulData[filterData.prop]" disabled="true" placeholder="请选择">
								</view>
							</view>
						</view>
						
						<!-- 树联控件 -->
						<view v-if="filterData.jnpfKey == 'treeSelect'">
							<view class="staff staffinfo border-bottom-E3E3E5">
								<view class="staffname"><label>{{filterData.label}}</label></view>
								<view class="advanceicon inputBox">
									<!-- <input type="text" placeholder="请选择" v-model="resulData[filterData.prop]"> -->
									<u-input v-model="resulData[filterData.prop]" type="select" placeholder="请输入" @tap='treeEvent(filterData.prop,filterData.multiple,filterData.jnpfKey)'/>
								</view>
							</view>
						</view>
						
						<!-- 级联控件 -->
						<view v-if="filterData.jnpfKey == 'cascader'">
							<view class="staff staffinfo border-bottom-E3E3E5">
								<view class="staffname"><label>{{filterData.label}}</label></view>
								<view class="advanceicon inputBox">
									<!-- <input type="text" placeholder="请选择" v-model="resulData[filterData.prop]"> -->
									<u-input v-model="resulData[filterData.prop]" type="select"  placeholder="请输入" @tap='treeEvent(filterData.prop,filterData.multiple,filterData.jnpfKey)'/>
								</view>
							</view>
						</view>
						
						
						<!-- 日期范围 -->
						<view v-if="filterData.jnpfKey == 'dateRange'" @tap.stop="rangeShow(filterData)">
							<view class="staff staffinfo border-bottom-E3E3E5">
								<view class="staffname"><label>{{filterData.label}}</label></view>
								<view class="advanceicon inputBox">
									<input type="text" placeholder="请选择" v-model="resulData[filterData.prop]">
								</view>
							</view>
						</view>
						
						
						<!-- 开关 -->
						<view v-if="filterData.jnpfKey == 'switch'">
							<view class="staff staffinfo border-bottom-E3E3E5">
								<view class="staffname"></text><label>{{filterData.label}}</label></view>
								<view class="advanceicon inputBox">
									<switch @change="switchChange($event,filterData)" style="transform:scale(0.7)" v-model="resulData[filterData.prop]" :checked="resulData[filterData.prop]"/>
								</view>
							</view>
						</view>
						
						<view v-if="filterData.jnpfKey == 'billRule'">
							<view class="staff staffinfo border-bottom-E3E3E5">
								<view class="staffname"></text><label>{{filterData.label}}</label></view>
								<view class="advanceicon inputBox">
									<input type="text" v-model="resulData[filterData.prop]" disabled=true placeholder="系统自动生成">
								</view>
							</view>
						</view>
						
						
						<!-- 数字框 -->
						<view v-if="filterData.jnpfKey == 'numInput'">
							<view class="staff staffinfo border-bottom-E3E3E5" @tap="filterFn">
								<view class="staffname"></text><label>{{filterData.label}}</label></view>
								<view class="advanceicon inputBox">
									<input type="number" placeholder="请输入" @input="hideKeyboard($event,filterData.prop)" v-model="resulData[filterData.prop]">
								</view>
							</view>
						</view>
						
						
						<!-- 选择框 -->
						<view class="staff staffinfo border-bottom-E3E3E5" v-else-if="filterData.jnpfKey == 'radio' || filterData.jnpfKey == 'checkbox' || filterData.jnpfKey == 'select' || filterData.jnpfKey == 'time' || filterData.jnpfKey == 'date'" @tap="selectClick(filterData)">
							<view class="staffname"></text>{{filterData.label}}</view>
							<view class="advanceicon inputBox" :key="index">
								<input type="text" v-if="filterData.jnpfKey == 'radio'" v-model="resulData[filterData.prop]" :name="filterData.prop" placeholder="请选择" disabled="true">
								<input type="text" v-if="filterData.jnpfKey == 'checkbox'" v-model="resulData[filterData.prop]" :name="filterData.prop" placeholder="请选择" disabled="true">
								<input type="text" v-if="filterData.jnpfKey == 'select'" v-model="resulData[filterData.prop]" :name="filterData.prop" placeholder="请选择" disabled="true">
								<input type="text" v-if="filterData.jnpfKey == 'time'" v-model="resulData[filterData.prop]" :name="filterData.prop" placeholder="请选择" disabled="true">
								<input type="text" v-if="filterData.jnpfKey == 'date'" v-model="resulData[filterData.prop]" :name="filterData.prop" placeholder="请选择" disabled="true">
							</view>
						</view>
					</view>
				</view>
				<view class="flow-button">
					<button class="btn-same btn-keep" form-type="reset" :disabled="scanType">重置</button>
					<button class="btn-same btn-submit" @tap="retrieval" hover-class="com-hover-btn">检索</button>
				</view>
				<!-- <button form-type="submit">Submit</button>
				<button form-type="reset">Reset</button> -->
			</form>
			
			<view class="noContent" v-else style="padding: 100rpx 0;">
				<img :src="nodata" alt="">
				<view class="">
					未添加筛选字段
				</view>
			</view>
		</uni-popup>
		<!-- 底部tree选择 -->
		<uni-popup type="bottom" mode="insert" :mask-click="true" ref="process">
			<view class="uni-share">
				<view class="uni-share-content">
					<view>
						<ly-tree 
							:tree-data="treeSelectData"
							:defaultExpandAll= defaultExpandAll
							node-key="id" 
							:props="props"
							ref="treeSelect"
							@node-expand="handleNodeExpand" 
							@node-click="handleNodeClick" />
					</view>
					<text class="uni-share-content-text"></text>
				</view>
				<!-- <text class="uni-share-btn" @click="cancel('share')">取消</text> -->
			</view>
		</uni-popup>
		<rangePicker
			:visible.sync="rangeVisible"
			mode="range" 
			startYear="2021" 
			endYear="2160"
			:value="rangeVal"
			:current="true"
			@confirm="rangeConfirm($event,'range')"
			@cancel="rangeCancel"
			ref="range" 
		></rangePicker>
		<w-picker :mode="mode" :pickerList="pickerList" ref="picker" :isSearchShow="isSearchShow"></w-picker>
		<tki-tree ref="tree" :range="treeData" rangeKey="fullName" :multiple="multiple" :selectParent="selectParent"></tki-tree>
		<mpvue-city-picker :themeColor="themeColor" ref="CityPicker" :pickerValueDefault="cityPickerValueDefault"
		 @onCancel="onCancel" @onConfirm="onConfirm">
		 </mpvue-city-picker>
	</view>
</template>

<script>
	import helper from '@/common/js/helper.js'
	import config from '@/common/js/config.js'
	import jnpf from '@/common/js/jnpf.js'
	import uniFab from '@/components/uni-fab/uni-fab.vue'
	import uniSwipeAction from '@/components/uni-swipe-action/uni-swipe-action.vue'
	import uniSwipeActionItem from '@/components/uni-swipe-action-item/uni-swipe-action-item.vue'
	import uniPopup from '@/components/uni-popup/uni-popup.vue'
	import tkiTree from '@/components/tki-tree/tki-tree.vue'
	import wPicker from '@/components/w-picker/w-picker.vue'
	
	import rangePicker from '@/components/range-picker/range-picker.vue'
	import mpvueCityPicker from '@/components/mpvue-citypicker/mpvueCityPicker.vue'
	import {
		initPicker,
		initDays
	} from "@/common/util.js";
	
	
	export default {
		components: {
			uniFab,
			uniSwipeAction,
			uniSwipeActionItem,
			uniPopup,
			wPicker,
			tkiTree,
			
			rangePicker,
			mpvueCityPicker,
		},
		data() {
			return {
				props:{
					children: 'children', // 指定子树为节点对象的某个属性值
					label: 'fullName', // 指定节点标签为节点对象的某个属性值
					disabled: 'disabled' ,//	指定节点选择框是否禁用为节点对象的某个属性值
					value: 'id'
				},
				cityPickerValueDefault: [0, 0, 1],
				themeColor: '#007AFF',
				treeSelectOption:[],
				defaultExpandAll:true,
				treeSelectData:[],
				rangeVal:['2021-1-1','2120-04-02'],
				rangeVisible:false,
				isSearchShow:false,
				_listAll:[],
				pickerList:[],
				mode:'',//底部弹窗分类
				salesmanNameList:[],
				depList:[],
				resulData:[],//多选，单选，下拉的value
				comList:[],
				userList:[],
				posList:[],
				dicList:[],
				treeData:[],
				multiple:false,
				selectParent:false,/* 父级可选 */
				retrievalData: null,
				ConfigData: [],
				featuresId: '',
				current: 0,
				currentTarget:0,
				search: '',
				listId: '',
				fields:[],
				formData:{},//主表model
				checkbox:[],/* 多选框 */
				rows: 15,
				page: 1,
				total: 1,
				height: 0,
				filterHeight:600,
				dataList: [],
				optionsList:[],
				dataModel:{},
				sortData: [],
				numberValue:null,
				filter:[],
				modelList:{},//存list
				modelJnpfKey:{},//存jnpfkey
				options: [{
					text: '删除',
					style: {
						backgroundColor: '#dd524d'
					}
				}],
				horizontal: 'right',
				vertical: 'bottom',
				direction: 'horizontal',
				pattern: {
					color: '#7A7E83',
					backgroundColor: '#fff',
					selectedColor: '#007AFF',
					buttonColor: "#007AFF"
				},
				isBillAsc: false,
				isBillDesc: false,
				isDateAsc: false,
				isDateDesc: false,
				years: [],
				months: [],
				days: [],
				dateValue: [],
				visible: true,
				isStartVis: false,
				isEndVis: false,
				indicatorStyle: `height: ${Math.round(uni.getSystemInfoSync().screenWidth/(750/100))}px;`,
				queryJson: {
					keyword: '',
					startTime: '',
					endTime: '',
					enabledMark: ""
				},
				isNoData: false,
				tables:[],
				nodata: config.Resources.message.nodata,
				dynamicList:[],
				dynamicModel:{},
				isToUpperCase:true,/*, 切换大小写 */
				scanType: false,/* 判断是否预览 */
				prop:{
					label: "label",
					value: "value"
				},
				listDetail:{},
				attributeList:[]
			}
		},
		
		onLoad(e) {
			/* 判断是否预览 */
			this.scanType = Object.prototype.hasOwnProperty.call(e,'type')
			
			uni.showLoading({
				title: '加载中...',
				mask: true
			});
			setTimeout(function () {
			    uni.hideLoading();
			}, 2000);
			
			
			/* 动态修改标题 */
			let title = uni.getStorageSync("title");
			uni.setNavigationBarTitle({
				title:title.F_FullName
			});
			
			this.dateValue = helper.newdefaultVal('date');
			const data = initPicker(helper.getDateYear('start'), helper.getDateYear('end'), "date", 1);
			this.years = data.years;
			this.months = data.months;
			this.days = data.days;
			this.featuresId = e.id
			let height = wx.getSystemInfoSync().windowHeight
			// this.init();
			
		},
		
		onShow() {
			/* 调用页面初始 */
			this.init();
			uni.showLoading({
				title: '加载中...',
				mask: true
			});
			
			setTimeout(function () {
			    uni.hideLoading();
			}, 2000);
			
			
			this.dataList.length = 0;
			this.isNoData = false;
			// this.$forceUpdate();
		},
		
		methods: {
			init() {
				this.select();
				let _this = this;
				/* 获取表单配置列表 */
				helper.ajax({
					url: `/api/VisualDevelopment/Model/app/${this.featuresId}/Config`,
					method: 'GET',
					success: res => {
						
						_this.flowEngine(res)
					}
				});
			},
			
			/* 初始化处理 */
			async flowEngine(res){
				this.getList();
				//判断有表还是无表
				this.tables = JSON.parse(res.data.data.tables);
				let formData = JSON.parse(res.data.data.formData);
				let fields = formData.fields;
				this.fields = fields;
				
				let ConfigList = JSON.parse(res.data.data.columnData);
				
				/* 排序赋值 */
				this.sortData = ConfigList.sortList
				/* 筛选赋值 */
				this.filter = ConfigList.searchList
				
				/* 动态筛选框高度 */
				let len = this.filter.length
				if(len == 0){
					this.filterHeight = 0;
				}else if(len > 0 && len <= 3){
					this.filterHeight = 96*3
				}else if(len > 3 && len <= 5){
					this.filterHeight = 96*5
				}else if(len > 7){
					this.filterHeight = 600
				}
				this.ConfigData = ConfigList.columnList
				this.page = 1;
				for(let i =0;i<fields.length;i++){
					let __vModel__ = fields[i].__vModel__;
					let jnpfKey = fields[i].__config__.jnpfKey;
					this.listDetail = {}
					this.listDetail.vModel = __vModel__;
					this.listDetail.jnpfKey = jnpfKey;
					this.listDetail.label = fields[i].__config__.label
					this.attributeList.push(this.listDetail)
					
					/* 保存jnpfKey */
					this.modelJnpfKey[__vModel__] = jnpfKey;
					/* 保存树联options */
					if(fields[i].__config__.jnpfKey=='treeSelect'){
						this.treeSelectOption = fields[i].options;
						uni.setStorageSync("treeSelectOption",this.treeSelectOption)
					}
					
					/* 选择框 */
					if(fields[i].__config__.jnpfKey=='radio' || fields[i].__config__.jnpfKey=='checkbox' || fields[i].__config__.jnpfKey=='select'){
						let _options = [];
						if(fields[i].__config__.dataType == 'static'){
							if(fields[i].__slot__){
								_options =  fields[i].__slot__.options;
							}else if(fields[i].__config__.options){
								_options = fields[i].__config__.options;
							}
						}else if( fields[i].__config__.dataType == 'dictionary'){
							_options = jnpf.dictionaryData(fields[i].__config__.dictionaryType)
						}else if( fields[i].__config__.dataType == 'dynamic'){
							let propsUrl = fields[i].__config__.propsUrl;
							await this.dynamicSelect(propsUrl)
							_options = this.dynamicList
							
						}
						let _defaultValue = fields[i].__config__.defaultValue;//选择框中的默认值
						let _listAll = [];
						let _chebox = [];
						let _cheboxValue = [];
						for(let k=0;k<_options.length;k++){
							let id = _options[k].id
							let _list ={
							   label:"",
							   value:"",
							   checked:false,
							};
							
						if(fields[i].__config__.dataType == 'static'){
							_list.value = _options[k].id;
							_list.label = _options[k].fullName;
						}else if(fields[i].__config__.dataType == 'dictionary'){
							_list.label = _options[k].label;
							_list.value = _options[k].id;
						}else if(fields[i].__config__.dataType == 'dynamic'){
							let propsLabel = fields[i].__config__.props.label;
							let propsValue = fields[i].__config__.props.value;
							let props = fields[i].__config__.props
							
							for(let i in props){
								this.dynamicModel.label = props.label
								this.dynamicModel.value = props.value
							}
							
							_list.label = _options[k][this.dynamicModel.label];
							_list.value = _options[k][this.dynamicModel.value];
						}
						_listAll[k]=_list;
						}
						this.$set(this.dataModel,""+__vModel__+"",_listAll);
						this.$set(this.optionsList,""+__vModel__+"",_listAll);
						fields[i].disabled=true;
					} 
				}
			
			},
			
			
			/* 渲染列表页 */
			getList(){
				let _this = this;
				this.formData = {};
				this.resulData = {},
				helper.ajax({
					url: `/api/VisualDevelopment/Model/app/${this.featuresId}/List`,
					method: 'GET',
					data: {
						pageSize: this.rows, //每页行数
						currentPage: 1, //当前页
						sort: 'asc',
					},
					success: res => {
						
						let _total = Math.ceil(res.data.data.pagination.total / res.data.data.pagination.pageSize)
						this.total = _total;
						let data = res.data.data.list;
						
						if(data.length == 0){
							this.isNoData = true
						}
						this.dataList =[];
						for(let i=0;i<data.length;i++){
							let _showList = [];
							let _value = data[i];
							for(let n=0;n<this.ConfigData.length;n++){
								let prop = this.ConfigData[n].prop;
								let label = this.ConfigData[n].label;
								let _show = {};
								_show.id = _value.id;
								_show.label = label;
								_show.value = _value[prop];
								if(_value[prop]!=undefined){
									for(let key in data[i]){
										if(key == this.attributeList[n]['vModel']){
											if(this.attributeList[n]['jnpfKey'] == 'checkbox'){
												_show.value = _value[prop].toString();
											}
										}
									}
								}
								_showList.push(_show);
							}
							this.dataList.push(_showList);
						}
						this.page = 1;
					}
				})
			},
			
			/* 检索 */
			retrieval() {
				if(this.scanType){
					return helper.msg('功能预览不支持数据检索')
				}
				this.$refs.cucreen.close();
				let form = {
					pageSize: this.rows, //每页行数
					currentPage: 1, //当前页
					json:this.formData,
				}
				
				helper.ajax({
					url: `/api/VisualDevelopment/Model/app/${this.featuresId}/List`,
					method: 'GET',
					data: form,
					success: res => {
						let _total = Math.ceil(res.data.data.pagination.total / res.data.data.pagination.pageSize)
						this.total = _total;
						let data = res.data.data.list;
						this.dataList =[];
						for(let i=0;i<data.length;i++){
							let _showList = [];
							let _value = data[i];
							for(let n=0;n<this.ConfigData.length;n++){
								let prop = this.ConfigData[n].prop;
								let label = this.ConfigData[n].label;
								let _show = {};
								_show.id = _value.id;
								_show.label = label;
								_show.value = _value[prop];
								if(_value[prop]!=undefined){
									for(let key in this.formData){
										if(key == this.attributeList[n]['vModel']){
											if(this.attributeList[n]['jnpfKey'] == 'checkbox'){
												_show.value = _value[prop].toString();
											}
										}
									}
								}else{
									_show.value = '';
								}
								_showList.push(_show);
							}
							this.dataList.push(_showList);
						}
						this.page = 1;
					},
					
				});
			},
			
			
			
			/* 远端数据 */
			dynamicSelect(id) {
				let apiKey = uni.getStorageSync('apiKey');
				let baseUrlObj = config.Global.baseUrl;
				let baseUrl = config.Global.baseUrl[apiKey].apiUrl;
				const token = uni.getStorageSync(config.Global.cache + '_Token');
				let _this = this
				return new Promise((resolve,reject) => {
					uni.request({
						url: baseUrl+'/api/DataInterface/'+id+'/Actions/Response',
						header: {
							'Authorization': token ,//自定义请求头信息
							'content-type': 'application/json;charset=UTF-8'
						},
						// dataType: 'json',
						method:'GET',
						success: (res) => {
							
							let treedata = res.data.data;
							_this.dynamicList = treedata;
							
							uni.setStorageSync('dynamicList',_this.dynamicList)
							resolve(res)
						},
						fail: (err) => {
							reject(err)
						}
					})
				})
			},
			
			switchChange(e,item){
				const switchModel = item.prop
				this.$set(this.resulData,switchModel,e.detail.value)
				this.$set(this.formData,switchModel,e.detail.value)
			},
			
			
			/* 日期范围 */
			rangeShow(item,index){
				uni.hideKeyboard();
				this.rangeVisible = true
				
				uni.setStorage({
					key:"rangeData",
					data:item
				})
			},
			
			/* 时间范围点击确定 */
			rangeConfirm(res,type){
				let dateArr = [];
				let dateStart = res
				let dateEnd = res
				dateStart = dateStart.substr(0, dateStart.indexOf("至"));
				dateEnd = dateEnd.substr(-10, dateEnd.indexOf("至"));
				let dateStart2 = Date.parse(dateStart);
				let dateEnd2 = Date.parse(dateEnd);
				dateArr.push(dateStart2,dateEnd2)
				
				
				let item = uni.getStorageSync('rangeData');
				let rangeModel = item.prop;
				this.$set(this.formData,""+rangeModel+"",dateArr);
				this.$set(this.resulData,""+rangeModel+"",res);
				
			},
			
			/* 时间范围点击取消 */
			rangeCancel(){
				
			},
			
			/* 公司，部门，岗位，用户树 */
			select(){
				this.posList = uni.getStorageSync('postList');
				this.depList = uni.getStorageSync('depList');
				this.userList = uni.getStorageSync('userList');
				this.comList = uni.getStorageSync('comList');
				this.dicList = uni.getStorageSync('dicList');
			},
			
			
			
			/* 树联控件 */
			// uni-app中emit触发的方法只能接受一个参数，所以会回传一个对象，打印对象即可见到其中的内容
			treeEvent(Vmodel,isMultiple,jnpfkey,children,index){
				uni.hideKeyboard();
				uni.setStorageSync("Vmodel",Vmodel);
				let obj = {
					children:children,
					jnpfkey:jnpfkey,
					isMultiple:isMultiple,
					index:index
				}
				uni.setStorageSync("obj",obj);
				this.treeSelectData = this.treeSelectOption
				
				this.$refs.process.open();
			},
			
			/* 树联控件 */
			handleNodeClick(obj) {
				uni.hideKeyboard();
				let childrenObj = uni.getStorageSync("obj")
				let salesmanKey;
				let salesmanModel;
				let nodePath = this.$refs.treeSelect.getNodePath(obj);
				let label = [];
				let _id_ = [];
				nodePath.forEach((item,i)=>{
					label.push(item.fullName)
					_id_.push(item.id)
				})
				this.multiple = childrenObj.isMultiple;
				let Vmodel = uni.getStorageSync('Vmodel');
				let _list = [];
				let _id = [];
				for(let i in obj){
					if(i == "data"){
						_list.push(obj[i].fullName);
						_id.push(obj[i].id);
					}
				}
				if(childrenObj.jnpfkey == 'cascader'){
					this.$set(this.formData,""+Vmodel+"",label.join('/'));
					this.$set(this.resulData,""+Vmodel+"",label.join('/'));
				}else{
					this.$set(this.formData,""+Vmodel+"",_list.toString());
					this.$set(this.resulData,""+Vmodel+"",_list.toString());
				}
				this.$refs.process.close()
			},
			/* 树联控件父级 */
			handleNodeExpand(e){
				uni.hideKeyboard();
			},
			
			
			/* 区域选择 */
			showMulLinkageThreePicker(item) {
				uni.hideKeyboard();
				this.$refs.CityPicker.show()
				
				uni.setStorage({
					key: "item",
					data: item
				});
				
			},
			/* 区域点击确定 */
			onConfirm(e) {
				
				let item = uni.getStorageSync('item');
				let label = e.label;
				let value = e.value
				this.$set(this.formData,""+item+"",label.toString());
				this.$set(this.resulData,""+item+"",label.toString());
				
			},
			/* 区域点击取消 */
			onCancel(e) {
				
			},
			
			
			
			/* 树事件 */
			salesmanName(Vmodel,isMultiple,jnpfkey) {
				uni.hideKeyboard();
				
					//主表树
				this.isSearchShow=false;
				this.selectParent = false;
				this.multiple = isMultiple;	
					if(jnpfkey =='comSelect'){
						this.optionsList[Vmodel] = this.comList;
						
					}else if(jnpfkey =='depSelect'){
						this.optionsList[Vmodel] = this.depList;
						
					}else if(jnpfkey =='posSelect'){
						this.optionsList[Vmodel] = this.posList;
						
					}else if(jnpfkey =='userSelect'){
						this.optionsList[Vmodel] = this.userList;
						
					}
				
				this.treeData = this.optionsList[Vmodel];
				
				this.$refs.tree._show();
				this.$eventHub.$off('treemodality');/* 移除自定义事件监听器 */
				/* 监听当前实例上的自定义事件。事件可以由vm.$emit触发。回调函数会接收所有传入事件触发函数的额外参数。*/
				this.salesmanNameList = [];
				this.$eventHub.$on('treemodality', (data) => {
					
					let _list = [];
					let _id = [];
					for(let i = 0;i<data.length;i++){
						_list.push(data[i].fullName);
						_id.push(data[i].id);
					}
					
					this.$set(this.resulData,""+Vmodel+"",_list.toString());
					
					this.$set(this.formData,""+Vmodel+"",_id.toString());
					
					this.$eventHub.$off('treemodality');/* 移除自定义事件监听器 */
				});
			},
			
			/* 获取数据列表 */
			selectClick(e){
				uni.hideKeyboard();//隐藏软键盘  
				let mode = "selector";
				let vModel = e.prop;
				this.pickerList = [];
				this.pickerList = this.dataModel[vModel]
				
				if(e.jnpfKey=='checkbox'){
					mode ="multiselector"
					
				}else if(e.jnpfKey=='radio'){
					mode ="electionsingle"
					
				} else if(e.jnpfKey=='selector'){
					mode ="selector"
				} else if(e.jnpfKey=='time'){
					mode = "time"
				} else if(e.jnpfKey=='date'){
					mode = "date"
				}
				
				this.mode=mode;
				this.$refs.picker.show();
				this.$eventHub.$off('popupmodality');
				this.$eventHub.$on('popupmodality', (data) => {
					
					if(e.jnpfKey == 'time'){
						this.$set(this.formData,""+vModel+"",data.result);
						this.$set(this.resulData,""+vModel+"",data.result);
						return;
					}
					if(e.jnpfKey=='date'){
						// var date = new Date().getTime(dateResult);
						let dateResult = data.result
						let date = Date.parse(dateResult);
						
						this.$set(this.formData,""+vModel+"",date);
						this.$set(this.resulData,""+vModel+"",data.result);
						return;
					}
					
					if(e.jnpfKey=='checkbox'){
						let _list = [];
						let _label = [];
						let num=0;
						for(let i=0;i<this.pickerList.length;i++){
							if(this.pickerList[i].checked==true){
								_list[num] = this.pickerList[i].label;
								_label[num] = this.pickerList[i].value;
								num=num+1;
							}
						}
						let label = _label.toString();
						let list = _list.toString();
						this.$set(this.resulData,""+vModel+"",list);
						this.$set(this.formData,""+vModel+"",list);
						
					}else if(e.jnpfKey == 'select'){
						
						for(let i=0;i<this.pickerList.length;i++){
							let _value = helper.setSpinner(this.dataModel[vModel],data.result,this.prop);
							this.$set(this.resulData,""+vModel+"",data.result);
							this.$set(this.formData,""+vModel+"",data.result);
						}
					} else {
						for(let i=0;i<this.pickerList.length;i++){
							if(this.pickerList[i].checked==true){
								let _value = helper.setSpinner(this.dataModel[vModel],data.result,this.prop);
								this.$set(this.resulData,""+vModel+"",data.result);
								this.$set(this.formData,""+vModel+"",_value);
								
							}
						}
					}
					// this.dataModel[vModel] = this.pickerList
					this.$eventHub.$off('popupmodality');
				});
			},
			
			
			
			/* 保存筛选输入的值 */
			hideKeyboard(event,__vModel__) {
				/* 隐藏软键盘 */
				if (event.target.value === '123') {
					uni.hideKeyboard();
				}
				this.$set(this.formData,__vModel__,event.target.value)
				
			},
			
			
			/* 触底事件 */
			scrollButtonClick() {
				uni.showLoading({
					title: '加载中...',
					mask: true
				});
				if (this.total > this.page) {
					this.page += 1;
					//触底
					helper.ajax({
						url: `/api/VisualDevelopment/Model/app/${this.featuresId}/List`,
						method: 'GET',
						data: {
							pageSize: this.rows, //每页行数
							currentPage: this.page, //当前页
						},
						success: res => {
							
							let _total = Math.ceil(res.data.data.pagination.total / res.data.data.pagination.pageSize)
							this.total = _total;
							let data = res.data.data.list;
							this.dataList =[];
							for(let i=0;i<data.length;i++){
								let _showList = [];
								let _value = data[i];
								for(let n=0;n<this.ConfigData.length;n++){
									let _show = {};
									_show.id = _value.id;
									_show.label = this.ConfigData[n].label;
									_show.value = _value[this.ConfigData[n].prop];
									if(_value[this.ConfigData[n].prop]==undefined){
										_show.value = ""
									}
									_showList.push(_show);
								}
								this.dataList.push(_showList);
							}
							this.page = 1;
						}
					});
				}
				uni.hideLoading();
			},
			
			/* 点击跳转form表单 */
			featuresDetail(item) {
				let url = './form?id='+ item[0].id+"&featuresId="+this.featuresId
				if(this.scanType){
					url = './form?id='+ item[0].id+"&featuresId="+this.featuresId+'&type='+this.scanType
				}
				uni.navigateTo({
					url: url
				})
			},
			
			/* 删除列表 */
			removeDetils(item, index) {
				if(!this.scanType){
					helper.ajax({
						url: `/api/VisualDevelopment/Model/app/${this.featuresId}/`+item[0].id,
						method: 'Delete',
						success: res => {
							this.dataList.splice(index, 1);
							helper.msg(res.data.msg, 'success');
							if(this.dataList.length == 0){
								this.isNoData = true
							}
						}
					});
				}
			},
			
			/* 点击添加 */
			creqateopen() {
				let url = './form?featuresId=' + this.featuresId
				if(this.scanType){
					url = './form?featuresId=' + this.featuresId+'&type='+this.scanType
				}
				uni.navigateTo({
					url: url
				})
				// if(this.scanType == undefined){/* 判断是否预览 */
				// 	uni.navigateTo({
				// 		url: './form?featuresId=' + this.featuresId
				// 	})
				// }
			},
			
			/* 排序 */
			orderSort() {
				this.$refs.popup.open();
				// if(this.scanType == undefined){/* 判断是否预览 */
				// 	this.$refs.popup.open();
				// }
			},
			
			/* 筛选 */
			cucreen() {
				this.$refs.cucreen.open();
				// if(this.scanType == undefined){/* 判断是否预览 */
				// 	this.$refs.cucreen.open();
				// }
			},
			
			/* 重置 */
			reset(e) {
				
				this.$refs.cucreen.close();
				this.getList()
			},
			
			
			
			/* 筛选 */
			filterFn(e){
				// this.$refs.cucreen.close();
				this.isBillAsc = false;
			},

			// 排序升序
			billAsc(e) {
				if(this.scanType){
					return helper.msg('功能预览不支持数据排序')
				}
				let _sidx = e.prop;
				this.$refs.popup.close();
				if(!this.scanType){
					helper.ajax({
						url: `/api/VisualDevelopment/Model/app/${this.featuresId}/List`,
						method: 'GET',
						data: {
							pageSize: this.rows, //每页行数
							currentPage: 1, //当前页
							sort: 'asc',
							sidx: _sidx
						},
						success: res => {
							
							let _total = Math.ceil(res.data.data.pagination.total / res.data.data.pagination.pageSize)
							this.total = _total;
							let data = res.data.data.list;
							this.dataList =[];
							for(let i=0;i<data.length;i++){
								let _showList = [];
								let _value = data[i];
								for(let n=0;n<this.ConfigData.length;n++){
									let _show = {};
									_show.id = _value.id;
									_show.label = this.ConfigData[n].label;
									_show.value = _value[this.ConfigData[n].prop];
									if(_value[this.ConfigData[n].prop]==undefined){
										_show.value = ""
									}
									_showList.push(_show);
								}
								this.dataList.push(_showList);
							}
							this.page = 1;
						}
					});
				}
			},
			
			/* 降序 */
			billDesc(e) {
				if(this.scanType){
					return helper.msg('功能预览不支持数据排序')
				}
				let _sidx = e.prop;
				this.$refs.popup.close();
				if(!this.scanType){
					helper.ajax({
						url: `/api/VisualDevelopment/Model/app/${this.featuresId}/List`,
						method: 'GET',
						data: {
							pageSize: this.rows, //每页行数
							currentPage: 1, //当前页
							sort: 'desc',
							sidx: _sidx
						},
						success: res => {
							
							let _total = Math.ceil(res.data.data.pagination.total / res.data.data.pagination.pageSize)
							this.total = _total;
							let data = res.data.data.list;
							this.dataList =[];
							for(let i=0;i<data.length;i++){
								let _showList = [];
								let _value = data[i];
								for(let n=0;n<this.ConfigData.length;n++){
									let _show = {};
									_show.id = _value.id;
									_show.label = this.ConfigData[n].label;
									_show.value = _value[this.ConfigData[n].prop];
									if(_value[this.ConfigData[n].prop]==undefined){
										_show.value = ""
									}
									_showList.push(_show);
								}
								this.dataList.push(_showList);
							}
							this.page = 1;
						}
					});
				}
			},
		},
		mounted() {
			/* 获取高度 */
			uni.getSystemInfo({
				success: (res) => {
					this.height = res.windowHeight;
				}
			});
		}
	}
</script>

<style lang="scss" scoped>
	page {
		background-color: #f0f2f6;
	}
	.content{
		/* #ifdef MP-WEIXIN */
		background-color: #f0f2f6;
		/* #endif */
	}
	.uni-share {
		/* #ifndef APP-NVUE */
		display: flex;
		flex-direction: column;
		/* #endif */
		background-color: #fff;
	}
	.uni-share-content {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: row;
		flex-wrap: wrap;
		// justify-content: center;
		padding: 15px;
		height: 500rpx;
		overflow-y: scroll;
	}
	
	
	.uni-share-content-image {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: row;
		// justify-content: center;
		align-items: center;
		width: 100%;
		padding: 20rpx 0;
		overflow: hidden;
		border-radius: 10rpx;
	}
	
	.uni-share-content-text {
		font-size: 26rpx;
		color: #333;
		padding-top: 5px;
		padding-bottom: 10px;
	}
	.uni-share-btn {
		height: 90rpx;
		line-height: 90rpx;
		font-size: 14px;
		border-top-color: #f5f5f5;
		border-top-width: 1px;
		border-top-style: solid;
		text-align: center;
		color: #666;
	}
	
	

	.search-input {
		background: #FFFFFF;
		// margin-top: 120upx;
	}

	.search-cell {
		margin: 0 auto;
		overflow: hidden;
		height: 100upx;
		align-content: center;
		display: flex;
		flex-direction: row;
		flex-wrap: wrap;
		justify-content: center;
		background-color: #FFFFFF;
		height: 100upx;
	}
	
	.search-item {
		width: 68%;
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: space-between;
	}

	.screen-btn {
		background-color: #FFFFFF;
		display: flex;
		align-items: center;
		justify-content: center;
		border-radius: 50%;
		color: #999999;
	}

	.screen-btn text {
		padding-right: 10upx;
	}

	.item {
		
		border-radius: 10upx;
		width: 100%;

		.jn-item-cell {
			padding:20rpx 10rpx;
			background-color: #FFFFFF;
			.jn-list-cell {
				padding: 0 20upx;
				margin-bottom: 10upx;
				justify-content: space-between;
				/* #ifndef MP-WEIXIN */
				&.cell {
					height: 48upx;
					padding: 30rpx 20rpx;
				}
				/* #endif */
				
			}
		}

		.head {
			height: 66upx;
			border-bottom: 1upx solid #e5e5e5;
		}
	}

	.popup-box {
		background-color: #fff;
		box-sizing: border-box;
	}

	// .staff {
	// 	width: 100%;
	// 	height: 96rpx;
	// 	display: flex;
	// 	background-color: #fff;
	// 	align-items: flex-start;
	// }

	.staffinfo {
		width: 91%;
		height: 96rpx;
		font-size: 28rpx;
		display: flex;
		flex-direction: row;
		vertical-align: hiddle;
		margin-left: 30rpx;
		align-items: center;
		justify-content: space-between;
		.inputBox{
			display: flex;
			flex-direction: row;
			width: 100%;
			flex-grow: 2;
			padding-left: 20rpx;
		}
		uni-input{
			width: 100% !important;
		}
	}

	.staffname {
		width: 30%;
		display: flex;
		white-space: nowrap;
		align-items: center;
		color: #3A3A3A;
		font-size: 32rpx;
	}

	.radio {
		padding-right: 7%;
		display: flex;
		flex-direction: row;
		width: 170rpx;
		justify-content: space-between;
	}

	picker-view {
		width: 100%;
		height: 396rpx;
		margin-top: 20rpx;
	}

	.picker-item {
		line-height: 100rpx;
		text-align: center;
	}
</style>
